package com.jas.ui;
//@author A0098803W
import java.util.Scanner;

import com.jas.common.CommandFormatException;
import com.jas.common.DateFormatException;
import com.jas.common.EventDateException;
import com.jas.common.Language;
import com.jas.common.SearchException;
import com.jas.logic.EventIdException;
import com.jas.logic.LogicAPI;
import com.jas.storage.StorageException;

/**
 * This class handles operations related to the program display
 * 
 * 
 * 
 */

public class JasDisplayHandler {

	private LogicAPI logicAPI;
	//@author A0098803W
	/**
	 * This constructor initialises JasDisplayHandler object.
	 * 
	 * @param args
	 *            User's input parameter.
	 */
	public JasDisplayHandler(LogicAPI logicAPI) {
		this.logicAPI = logicAPI;
	}

	//@author A0098803W
	/**
	 * This method executes any command entered by the user.
	 * 
	 */
	public void executeUserCommand() {

		Scanner sc = new Scanner(System.in);
		boolean code = true;
		String input;
		DisplayControl displayControl = new DisplayControl(logicAPI);
		do {
			System.out.print(Language.getString("PROMPT_COMMAND"));
			input = sc.nextLine();

			try {
				displayControl.executeUserCommand(input);
			} catch (CommandFormatException | StorageException
					| EventIdException | DateFormatException | SearchException | EventDateException e) {
				System.out.println(e.getMessage());
			}

		} while (code);

		sc.close();
	}

}